package com.hinnotek.warehouse

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.hinnotek.warehouse.ui.fragment.MainFragment
import com.lee.common.di.BASE_URL
import com.hinnotek.warehouse.utils.CustomUpdateParser
import com.lee.common.utils.ACTIVITY_MAIN_NEW
import com.lee.common.utils.MyActivityManager
import com.qmuiteam.qmui.arch.QMUIFragmentActivity
import com.qmuiteam.qmui.arch.annotation.DefaultFirstFragment
import com.qmuiteam.qmui.arch.annotation.LatestVisitRecord
import com.xuexiang.xupdate.XUpdate

@DefaultFirstFragment(MainFragment::class)
@LatestVisitRecord
@Route(path = ACTIVITY_MAIN_NEW)
class MainActivity : QMUIFragmentActivity() {

    override fun getContextViewId(): Int {
        return R.id.main_fragment_activity
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
        MyActivityManager.instance.addActivity(this)
        updateVersion()
    }

    private fun updateVersion() {
        val updateUrl = BASE_URL +"app/manage/getNewUpdateVersion"
        XUpdate.newBuild(this)
            .updateUrl(updateUrl)
            .updateParser(CustomUpdateParser())
            .update()
    }

    override fun onDestroy() {
        MyActivityManager.instance.removeActivity(this)
        super.onDestroy()
    }

}